package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.entity.Category;
import com.leyou.item.entity.CategoryNames;
import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ShenMin
 * @date 2021/7/14 17:29
 * @description
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    @Autowired
    CategoryMapper categoryMapper;

    @Override
    public String queryCategoryNamesById(Long cid1,Long cid2,Long cid3) {
        CategoryNames categoryNames = categoryMapper.listCategoryNamesById(cid1,cid2,cid3);
        return categoryNames.getNames();
    }

    //根据分类id，查询商品分类
    @Override
    public List<CategoryDTO> listCategoryById(Long id) {
        List<Category> categoryList = this.query().eq("id", id).list();
        //List<CategoryDTO> categoryDTOList = categoryList.stream().map(CategoryDTO::new).collect(Collectors.toList());
        return CategoryDTO.convertEntityList(categoryList);
    }

    //根据分类id的集合，查询商品分类的集合
    @Override
    public List<CategoryDTO> listCategoryByIds(List<Long> ids) {
        List<Category> categoryList = this.query().in("id", ids).list();
        return CategoryDTO.convertEntityList(categoryList);
    }

    //根据品牌id，查询商品分类的集合
    @Override
    public List<CategoryDTO> listCategoryByBid(Long bid) {
        List<Category> categoryList = categoryMapper.listCategoryByBid(bid);
        return CategoryDTO.convertEntityList(categoryList);
    }

    //根据父类目id，查询子类目的集合
    @Override
    public List<CategoryDTO> listCategoryByPid(Long pid) {
        List<Category> categoryList = this.query().eq("parent_Id", pid).list();
        return CategoryDTO.convertEntityList(categoryList);
    }


}
